<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #canvas {
            border: 1px solid #333;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="200" height="200"></canvas>
    <script>
        /* 1、获取画布 */
        let canvas = document.getElementById("canvas");
        /* 2、获取绘制上下文 */
        let ctx = canvas.getContext("2d");
        /* 3、样式 */
        // ctx.lineWidth = 10;
        ctx.moveTo(50, 50)
        ctx.strokeStyle = "#ff2d51";
        ctx.lineTo(150, 150);
        // ctx.stroke(); // 先写这个就是黑色
        ctx.lineWidth = 10;
        // ctx.strokeStyle = "#ff2d51";
        ctx.stroke(); // 后写就是红色(先把样式设置好了，然后再开始画)
    </script>
</body>

</html>